package com.ruoyi.project.utils;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 格式:ITEMYYYYMMDD
 */
@Component
public class ProjectCode {

    private String date;
    @PostConstruct
    public void init(){
        reset();
    }
    @Scheduled(cron = "0 0 0 * * ?")
    private void reset(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        date= simpleDateFormat.format(new Date());
    }
    public String getCode(String s,String gs,String type){
        StringBuilder sb = new StringBuilder(type+gs.toUpperCase().charAt(0));
        String xm = SZM.getszm(s);
        if(xm.length()>6)
            xm=xm.substring(0,6);
        sb.append(xm);
        sb.append(date);
//        if (hasCon)
//            sb.append("H");
//        else
//            sb.append("N");
        String time = new Date().getTime()+"";
        sb.append(time.substring(9));
        return sb.toString();
    }


}
